From c6baa9bc250762988488ed28a22e67328b87c8eb Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 29 Mar 2013 09:38:34 +0100 Subject: [PATCH] broadway: Move surface open to server This way we can cache the last opened surface --- gdk/broadway/broadway-server.c | 63 +++++++++++++++++++++++++++++++++ gdk/broadway/broadway-server.h | 5 +++ gdk/broadway/broadwayd.c | 64 +++------------------------------- 3 files changed, 73 insertions(+), 59 deletions(-) diff --git a/gdk/broadway/broadway-server.c b/gdk/broadway/broadway-server.c index 5b6bb96eef..433876a62b 100644 --- a/gdk/broadway/broadway-server.c +++ b/gdk/broadway/broadway-server.c @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -1808,6 +1811,66 @@ broadway_server_ungrab_pointer (BroadwayServer *server, return serial; } +static const cairo_user_data_key_t shm_cairo_key; + +typedef struct { + void *data; + gsize data_size; +} ShmSurfaceData; + +static void +shm_data_unmap (void *_data) +{ + ShmSurfaceData *data = _data; + munmap (data->data, data->data_size); + g_free (data); +} + +cairo_surface_t * +broadway_server_open_surface (BroadwayServer *server, + guint32 id, + char *name, + int width, + int height) +{ + ShmSurfaceData *data; + cairo_surface_t *surface; + gsize size; + void *ptr; + int fd; + + size = width * height * sizeof (guint32); + + fd = shm_open(name, O_RDONLY, 0600); + if (fd == -1) + { + perror ("Failed to shm_open"); + return NULL; + } + + ptr = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0); + (void) close(fd); + + if (ptr == NULL) + return NULL; + + data = g_new0 (ShmSurfaceData, 1); + + data->data = ptr; + data->data_size = size; + + surface = cairo_image_surface_create_for_data ((guchar *)data->data, + CAIRO_FORMAT_RGB24, + width, height, + width * sizeof (guint32)); + g_assert (surface != NULL); + + cairo_surface_set_user_data (surface, &shm_cairo_key, + data, shm_data_unmap); + + return surface; +} + guint32 broadway_server_new_window (BroadwayServer *server, int x, diff --git a/gdk/broadway/broadway-server.h b/gdk/broadway/broadway-server.h index 4ef9338f81..7941bcdd56 100644 --- a/gdk/broadway/broadway-server.h +++ b/gdk/broadway/broadway-server.h @@ -78,5 +78,10 @@ gboolean broadway_server_window_move_resize (BroadwayServer * int y, int width, int height); +cairo_surface_t * broadway_server_open_surface (BroadwayServer *server, + guint32 id, + char *name, + int width, + int height); #endif /* __BROADWAY_SERVER__ */ diff --git a/gdk/broadway/broadwayd.c b/gdk/broadway/broadwayd.c index 1c06eb7613..94f4bd4367 100644 --- a/gdk/broadway/broadwayd.c +++ b/gdk/broadway/broadwayd.c @@ -140,62 +140,6 @@ region_from_rects (BroadwayRect *rects, int n_rects) return region; } -static const cairo_user_data_key_t shm_cairo_key; - -typedef struct { - void *data; - gsize data_size; -} ShmSurfaceData; - -static void -shm_data_unmap (void *_data) -{ - ShmSurfaceData *data = _data; - munmap (data->data, data->data_size); - g_free (data); -} - -cairo_surface_t * -open_surface (char *name, int width, int height) -{ - ShmSurfaceData *data; - cairo_surface_t *surface; - gsize size; - void *ptr; - int fd; - - size = width * height * sizeof (guint32); - - fd = shm_open(name, O_RDONLY, 0600); - if (fd == -1) - { - perror ("Failed to shm_open"); - return NULL; - } - - ptr = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0); - (void) close(fd); - - if (ptr == NULL) - return NULL; - - data = g_new0 (ShmSurfaceData, 1); - - data->data = ptr; - data->data_size = size; - - surface = cairo_image_surface_create_for_data ((guchar *)data->data, - CAIRO_FORMAT_RGB24, - width, height, - width * sizeof (guint32)); - g_assert (surface != NULL); - - cairo_surface_set_user_data (surface, &shm_cairo_key, - data, shm_data_unmap); - - return surface; -} - void add_client_serial_mapping (BroadwayClient *client, guint32 client_serial, @@ -337,9 +281,11 @@ client_handle_request (BroadwayClient *client, cairo_region_destroy (area); break; case BROADWAY_REQUEST_UPDATE: - surface = open_surface (request->update.name, - request->update.width, - request->update.height); + surface = broadway_server_open_surface (server, + request->update.id, + request->update.name, + request->update.width, + request->update.height); if (surface != NULL) { broadway_server_window_update (server, -- 2.30.2